package com.drugmanage.controller;

import com.drugmanage.Base.BaseController;
import com.drugmanage.annotations.Pms;
import com.drugmanage.dao.dto.TreeDto;
import com.drugmanage.entity.Module;
import com.drugmanage.model.ResultInfo;
import com.drugmanage.query.ModuleQuery;
import com.drugmanage.service.IModuleService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("user/module")
public class ModuleController extends BaseController {

    @Resource
    private IModuleService moduleService;


    @RequestMapping("index")
    public String index(){
        return "module";
    }

    @RequestMapping("queryAllModules")
    @ResponseBody
    public List<TreeDto> queryAllModules(Integer roleId){
        return moduleService.queryAllModules(roleId);
    }

    @RequestMapping("saveModule")
    @ResponseBody
    public ResultInfo saveModule(Module module){
        moduleService.saveModule(module);
        return success("资源添加成功");
    }
    @RequestMapping("updateModule")
    @ResponseBody
    public ResultInfo updateModule(Module module){
        moduleService.updateModule(module);
        return success("资源修改成功");
    }
    @RequestMapping("deleteModule")
    @ResponseBody
    public ResultInfo deleteModule(Integer[] ids){
        moduleService.deleteModule(ids[0]);
        return success("资源删除成功");
    }

    @RequestMapping("queryModulesByParams")
    @ResponseBody
    @Pms(acl = "888803")
    public Map<String,Object> searchModuleByParams(ModuleQuery moduleQuery){
        return moduleService.searchModuleByParams(moduleQuery);
    }

    @RequestMapping("queryModulesByGrade")
    @ResponseBody
    public List<Module> queryModulesByGrade(Integer grade){
        return moduleService.queryModulesByGrade(grade);
    }
}
